package com.fyg.controller;


import com.fyg.annotation.mySystemlog;
import com.fyg.domain.Article;
import com.fyg.domain.ResponseResult;
import com.fyg.service.IArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 文章表 前端控制器
 * </p>
 *
 * @author czx
 * @since 2024-11-14
 */
@RestController
@Api(tags = "文章管理")
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private IArticleService articleService;
    //http://localhost:8080/article/list
    @ApiOperation("查询全部文章")
    @GetMapping ("/list")
    public List<Article> test(){
        return articleService.list();
    }

    @ApiOperation("查询热门文章")
    @GetMapping("/hotArticleList")
    //http://localhost:7777/article/hotArticleList
    public ResponseResult hotArticleList(){
        ResponseResult result = articleService.hotArticleList();
        return result;
    }
    @ApiOperation("分页查询文章")
    @GetMapping("/articleList")
    //ResponseResult是huanf-framework工程的domain目录的类
    public ResponseResult articleList(Integer pageNum,Integer pageSize,Long categoryId){
        return articleService.articleList(pageNum,pageSize,categoryId);
    }
    @ApiOperation("文章详情")
    @GetMapping("/{id}")
    public ResponseResult getArticleDetail(@PathVariable("id") Long id){
        return articleService.getArticleDetail(id);
    }

    @PutMapping("/updateViewCount/{id}")
    @mySystemlog(xxbusinessName = "根据文章id从mysql查询文章")//接口描述，用于'日志记录'功能
    public ResponseResult updateViewCount(@PathVariable("id") Long id){
        return articleService.updateViewCount(id);
    }
}
